package _01_动态数组;

public class _162_寻找峰值 {

    public static void main(String[] args) {
        _162_寻找峰值 v = new _162_寻找峰值();
        int[] ins = new int[]{2, 1};
        System.out.println(v.findPeakElement(ins));
    }

    public int findPeakElement(int[] nums) {
        int left = 0; // 0
        int right = nums.length - 1; // 1
        while (left < right) {
            int mid = left + right >> 1;
            if (nums[mid] < (mid > 0? nums[mid - 1]: Integer.MIN_VALUE)) {
                right = mid - 1;
            } else if (nums[mid] < (mid < right? nums[mid + 1]: Integer.MIN_VALUE)) {
                left = mid + 1;
            } else {
                return mid;
            }
        }
        return left;
    }
}
